package com.mdlib.droid.model;


import java.io.Serializable;

/**
 * 作者：HQY on 17/5/26 15:37
 * 邮箱：hqy_xz@126.com
 */

public class AccountModel implements Serializable, Cloneable {
    public static final String TAG = "account_aurora";


    private static AccountModel instance;

    private String baseUrl;
    // 登录后sessionId
    private String sessionId;
    private String token;
    private String name;
    private String password;
    private boolean isLogin = false;
    private boolean isGuide = false;
    private boolean isBuy = false;
    private String uid;

    public static AccountModel getInstance() {
        if (instance == null) {
            synchronized (AccountModel.class) {
                Object object = MDAppUtils.restoreObject(TAG);
                if (object == null) {
                    object = new AccountModel();
                    MDAppUtils.saveObject(TAG, object);
                }

                instance = (AccountModel) object;
            }
        }
        return instance;
    }


    public void writeToCache() {
        MDAppUtils.saveObject(TAG, this);
    }

    public void reset() {
        clearData();
        MDAppUtils.saveObject(TAG, this);
    }

    public void clearCache() {
        clearData();
        MDAppUtils.saveObject(TAG, this);
    }

    private void clearData() {
        sessionId = "";
        token = "";
        name = "";
        password = "";
        uid = "";
        isLogin = false;
        isBuy = false;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }


    public boolean isLogin() {
        return isLogin;
    }

    public void setLogin(boolean login) {
        isLogin = login;
    }

    public boolean isGuide() {
        return isGuide;
    }

    public void setGuide(boolean guide) {
        isGuide = guide;
    }

    public String getName() {
        return name == null ? "" : name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password == null ? "" : password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean isBuy() {
        return isBuy;
    }

    public void setBuy(boolean buy) {
        isBuy = buy;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }
}
